package com.jy.api.domain;

import com.jy.api.signUpReq.admin.EmployeeSignUpReq;
import com.jy.api.signUpReq.admin.ShopmanSignUpReq;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by hanxi on 2017/7/8.
 * 员工表
 */
@Entity
@Data
@NoArgsConstructor
public class Employee {
    @Id
    @Column(length = 50)
    private String id;
    //名字
    private String name;

    private String code;
    //手机
    private String mobile;
    //身份
    private String status;
    //用户名
    private String username;
    //网吧编号
    private String storeId;
    //微信支付链接
    private String wechatPayUrl;
    //支付宝支付链接
    private String aliPayUrl;
    //营业额目标
    private int target;
    //员工头像
    private String photo;
    //是否上下班
    private boolean work = false;

    private boolean sendCouponEnabled=false;


    @ManyToOne
    private EmployeeGroup group;
    @Column(insertable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date addTime;
    @Column(insertable = false, updatable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;
    private boolean enabled = true;

    public Employee(String id, String name, String storeId, EmployeeGroup group, String username, String code) {
        this.id = id;
        this.name = name;
        this.storeId = storeId;
        this.group = group;
        this.username = username;
        this.code = code;
    }


    public boolean checkPayConfigUrl() {
        boolean status = true;
        if (group.getRoles().indexOf("POS") != -1 &&
                (StringUtils.isBlank(wechatPayUrl) ||
                        StringUtils.isBlank(aliPayUrl))
                ) {
            status = false;
        }

        return status;
    }

    /**
     * 校验是否为更新
     *
     * @param upReq
     * @return
     */
    public boolean checkRenew(EmployeeSignUpReq upReq) {

        if ((StringUtils.isNotBlank(aliPayUrl) &&
                !StringUtils.equals(aliPayUrl, upReq.getAliPayUrl())) ||
                (StringUtils.isNotBlank(wechatPayUrl) &&
                        !StringUtils.equals(wechatPayUrl, upReq.getWechatPayUrl()))) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 校验是否为更新
     *
     * @param supReq
     * @return
     */
    public boolean checkRenew1(ShopmanSignUpReq supReq) {

        if ((StringUtils.isNotBlank(aliPayUrl) &&
                StringUtils.equals(aliPayUrl, supReq.getAliPayUrl())) ||
                (StringUtils.isNotBlank(wechatPayUrl) &&
                        StringUtils.equals(wechatPayUrl, supReq.getWechatPayUrl()))) {
            return true;
        } else {
            return false;
        }
    }
}
